<%-- 
    Document   : userManager
    Created on : 2016-6-30, 19:42:14
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${base}/css/bootstrap-datetimepicker.min.css"/>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.min.js" ></script>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.zh-CN.js" ></script>
    </head>
    <style>
        .error{font-size: 1px; color: red}
    </style>

    <body ng-app="userManage" ng-controller="mainCtrl" style="padding-top: 10px;">

        <!--        <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理列表</strong> / <small>User list</small></div>
                </div>-->
        <!--        <hr>-->

        <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading"><span style="float: left">样本采集列表</span>
                    <div>
                        <input ng-model="searchContent"  placeholder="名字/ID" style="width:320px; float: left;margin-left: 20px" class="form-control input-sm" />
                        <button ng-click="getUsers()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>
                        <button ng-click="addUser()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;添加</button>
                        <button ng-click="plPrint()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;批量打印</button>
                        <button ng-click="getUsers()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-refresh"></span>&nbsp;&nbsp;刷新</button></div>
                   
                        
                        <div style="clear: both"></div>
                </div>    
            </div>

            <table class="table table-striped table-bordered  table-hover ">
                <thead>
                    <tr>
                        <th><input type="checkbox" ng-model="checkAll" ng-change="checked()"></th>
                        <th class="table-id">条码号</th>
<!--                        <th class="table-id">病人ID</th>-->
                        <th class="table-title">病人姓名</th>
                        <th class="table-type">性别</th>
<!--                        <th class="">电话</th>-->
                        <th class="table-author am-hide-sm-only">年龄</th>
                        <th class="table-date am-hide-sm-only">类型</th>
                        <th class="table-set">科室</th>
                        <th class="table-set">样本</th>
                        <th class="">项目</th>
                        <th class="">发送状态</th>
                        <th class="">结果状态</th>
                        <th class="">医院</th>
                        <th class="">其他</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="list in lists" ng-click='selectPatient(list)'>
                        <td id="td1"><input type="checkbox" ng-model="list.check" name="btn"></td>
                        <td>{{list.BARCODE}}</td>
<!--                        <td>{{list.PATIENTID}}</td>-->
                        <td>{{list.PATIENTNAME}}</td>
                        <td>{{list.SEX}}</td>
<!--                        <td class="am-hide-sm-only">{{list.PHONENO}}</td>-->
                        <td class="am-hide-sm-only">{{list.AGE}}</td>
                        <td class="am-hide-sm-only">{{list.STAYHOSPITALMODE}}</td>
                        <td class="am-hide-sm-only">{{list.SECTION}}</td>
                        <td class="am-hide-sm-only">{{list.SAMPLE}}</td>
                        <td class="am-hide-sm-only">{{list.EXAMINAIM}}</td>
                        <td class="am-hide-sm-only" ng-class="{ 'text-success':list.SEND_CENTER_STATUS==1}">{{list.SEND_CENTER_STATUS_NAME}}</td>
                        <td class="am-hide-sm-only" ng-class="{'text-danger':list.SEND_CENTER_STATUS==0, 'text-info':list.RETURN_RESULT_FLAG==1,'text-success':list.SEND_CENTER_STATUS==2}">{{list.RETURN_RESULT_FLAG_NAME}}</td>
                        <td class="am-hide-sm-only">{{list.hospital_name}}</td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button ng-click="printTM(list)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>打条码</button>
                                    <button ng-hide="list.SEND_CENTER_STATUS>0" ng-click="OpenUpdateModal(list)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>修改</button>
                                    <button ng-click="deleteInfo(list)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>&nbsp;删除</button>
                                     
                                    <button ng-show="!list.SEND_CENTER_STATUS" ng-click="sendCenter(list)" class="btn btn-info btn-xs"><span class="fa fa-send"></span>&nbsp;发送</button>
<!--                                    <button ng-click="printRpt(list)" class="btn btn-info btn-xs"><span class="fa fa-print">&nbsp;打报告</span></button>
                                     <button ng-show="list.RETURN_RESULT_FLAG==2" ng-click="previewRpt(list)" class="btn btn-info btn-xs" ><span class="fa fa-search">预览</span></button>-->
                                 <button  ng-show="list.RETURN_RESULT_FLAG==2" ng-click="printRpt(list)" class="btn btn-success btn-xs"><span class="fa fa-print"></span>&nbsp;打报告</button>
                                  <button  ng-show="list.RETURN_RESULT_FLAG==2" ng-click="previewRpt(list)" class="btn btn-success btn-xs"><span class="fa fa-bolt"></span>&nbsp;预览</button>
                             
                                </div>
                            </div>
                        </td>
                    </tr>

                </tbody>
            </table>
            <footer class="panel-heading">
                <div class="row">
                    <div style="text-align: center" >                
                        <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                    </div>
                </div>
            </footer>

        </div>

    </div>


    <!--<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>-->

    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">


                <!--  <label name="email">Your email</label>
                  <input type="email" name="email" ng-model="email" placeholder="Email Address" />-->

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="deteleInfo()"><span aria-hidden="true">&times;</span></button>
                    <h3 class="modal-title" id="myModalLabel" style="text-align:center ;">{{title}}样本</h3>
                </div>
                <div class="modal-body">
                    <form name="form" class="form-validation"> 
                        <table  class="cx-table">
                            <tr>
                                <td>姓名:</td>
                                <td><input type="text" class="form-control"  ng-model="name"></td>
                                <td>性别:</td>
                                <td>
                                    <select  class="form-control" style="width: 140px;" ng-model="sexed">
                                        <option ng-repeat="sex in sexs">{{sex.nan}}</option>
                                    </select>
                                </td>
                                <td>年龄:</td>
                                <td><input type="text" ng-model="age" class="form-control"></td>
                            </tr>
                            <tr>
                                <td>电话:</td>
                                <td><input type="text" class="form-control"ng-model="phoneno"> </td>
                                <td>床号:</td>
                                <td><input type="text" class="form-control"ng-model="ch"></td>
                                <td>类型:</td>
                                <td>
                                    <select  class="form-control" style="width: 140px;" ng-model="lxed">
                                        <option ng-repeat="l in lxs">{{l.lx}}</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>科室:</td>
                                <td><select  class="form-control" style="width: 140px;" ng-model="ksed" >
                                        <option ng-repeat="ks in ksmcs">{{ks.ksmc}}</option>
                                    </select></td>
                                <td>样本:</td>
                                <td><select  class="form-control" style="width: 140px;" ng-model="ybed">
                                        <option ng-repeat="yb in ybs">{{yb.SAMPLEDESCRIBE}}</option>
                                    </select>
                                </td>
                                <td>项目:</td>
                                <td>
                                    <select  class="form-control" style="width: 140px;" ng-model="xmed">
                                        <option ng-repeat="xm in xms">{{xm.ITEMNAME}}</option>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div class="modal-footer" >
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="deteleInfo()">取消</button>
                    <button type="button" class="btn btn-primary" ng-disabled="form.$invalid" ng-click="saveSample()" >保存</button>

                </div>
            </div>
        </div>

    </div>
</body>
</html>
<script>
  var app = angular.module("userManage", ['baseModule', 'ui.validate', 'ui.select', 'ui.bootstrap']);
app.controller("mainCtrl", function ($scope, base) {
    $scope.user = {};
    $scope.searchContent = "";
    $scope.data = {currentPage: 1};
    $scope.setPage = function (pageNo) {
        $scope.data.currentPage = pageNo;
    };
    $scope.pageChanged = function () {
        $scope.getUsers();
    };

    $scope.data.maxSize = 10;
    $scope.data.bigTotalItems = 20;
    $scope.data.bigCurrentPage = 1;
    $scope.data.pageSize = 10;
    $scope.getUsers = function () {//显示用户信息
        base.post("sample/getUserList", {pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage, searchContent: $scope.searchContent}).get(function (data) {
            if (data) {
                $scope.lists = data.list;
                $scope.data.bigTotalItems = data.totalRow;
                for (var i in  $scope.lists) {
                    if ($scope.lists[i].SEND_CENTER_STATUS == 0) {

                        $scope.lists[i].SEND_CENTER_STATUS_NAME = "未发送";

                    } else if($scope.lists[i].SEND_CENTER_STATUS == 1) {
                        $scope.lists[i].SEND_CENTER_STATUS_NAME = "已发送";
                        $scope.lists[i].SEND_CENTER_STATUS_FLAG = true;
                    }else{
                           $scope.lists[i].SEND_CENTER_STATUS_NAME = "已获取";
                        $scope.lists[i].SEND_CENTER_STATUS_FLAG = true;
                    }

                    if ($scope.lists[i].RETURN_RESULT_FLAG == 0) {
                        $scope.lists[i].RETURN_RESULT_FLAG_NAME = "无结果";
                    } else {
                        $scope.lists[i].RETURN_RESULT_FLAG_NAME = "有结果";
                    }
                }
            }
        })
    }
    $scope.getUsers();
    $scope.getKsmc = function () {
        base.post("sample/getKsmc", {}).get(function (data) {
            $scope.ksmcs = data;
            $scope.ksed = "输血科";
        });
    }
    $scope.getSampleType = function () {
        base.post("sample/getSampleType", {}).get(function (data) {
            $scope.ybs = data;
            $scope.ybed = "血浆";
        });
    }
    $scope.getXMZT = function () {
        base.post("sample/getXMZT", {}).get(function (data) {
            $scope.xms = data;
            $scope.xmed = "乙肝五项";
        });
    }
    $scope.sexs = [{nan: "男"}, {nan: "女"}];
    $scope.lxs = [{lx: "住院"}, {lx: "门诊"}];
    $scope.init = function () {
        $scope.getSampleType();
        $scope.getKsmc();
        $scope.getXMZT();
    }

    $scope.addUser = function () {//打开新增窗口
        $scope.title = "新增";
        $('#myModal').modal({
            show: true,
            backdrop: true
        })
        $scope.pk = null;
        $scope.name = null;
        $scope.phoneno = null;
        $scope.ch = null;
    };
    $scope.saveSample = function () {
        var sex = $("#sex").val();
        var lx = $("#lx").val();
        if ($scope.name == null) {
            steveConfrim("请输入姓名！");
        }
        if ($scope.pk) {
            base.post("sample/updateSample", {pk: $scope.pk, name: $scope.name, sex: $scope.sexed, birth: $scope.date, brpk: $scope.brpk,
                phone: $scope.phoneno, ch: $scope.ch, lx: $scope.lxed, ksmc: $scope.ksed, yb: $scope.ybed, xmm: $scope.xmed,age:$scope.age
            }).get(function (data) {
                if (data == "true") {
                    steveAl("修改成功!", 1000);
                    $("#myModal").modal("hide");
                    $scope.getUsers();
                } else {
                    steveAl("修改失败!", 1000);
                }
            });


        } else {
            base.post("sample/addSample", {name: $scope.name, sex: $scope.sexed, birth: $scope.date, phone: $scope.phoneno, ch: $scope.ch,
                lx: $scope.lxed, ksmc: $scope.ksed, yb: $scope.ybed, xmid: $scope.xmed,age:$scope.age
            }).get(function (data) {
                if (data == 'true') {
                    steveAl("添加成功", 1000);
                    $("#myModal").modal("hide");
                    $scope.getUsers();
                } else {
                    steveAl("保存失败!", 1000);
                }
            });
        }
    }
    $scope.OpenUpdateModal = function (item) {
        $scope.title = "修改";
        $('#myModal').modal({
            show: true,
            backdrop: true
        })
        $scope.pk = item.PK;
        $scope.brpk = item.brpk;
        $scope.name = item.PATIENTNAME;
        $scope.phoneno = item.PHONENO;
        $scope.ch = item.BED_NO;
        $scope.ksed = item.SECTION;
        $scope.ybed = item.SAMPLE;
        $scope.xmed = item.EXAMINAIM;
        $scope.sexed = item.SEX;
        $scope.lxed = item.STAYHOSPITALMODE;
        var date = new Date(item.BIRTHDAY).Format("yyyy-MM-dd");
        $('#datetimepicker').val(date);
    }

    $scope.deleteInfo = function (item) {
        steveConfrim("确定删除吗" + item.PATIENTNAME + "？", function () {
            base.post("sample/deleteInfo", {pk: item.PK, brpk: item.brpk}).get(function (data) {
                if (data == 'true') {
                    $scope.getUsers();
                } else {
                    steveAl("删除失败!", 1000);
                }

            });
        });
    };
    $scope.init();
    var pl = [];
    $scope.printTM = function (list) {
        pl.splice(0, pl.length);
        pl.push(list);
        localStorage.pl = JSON.stringify(pl);
        window.open("printTM.jsp");
    }
    $scope.checked = function () {
        if ($scope.checkAll == true) {
            for (var i = 0; i < $scope.lists.length; i++) {
                $scope.lists[i].check = true;
            }
        } else {
            for (var i = 0; i < $scope.lists.length; i++) {
                $scope.lists[i].check = false;
            }
        }
    }

    $scope.plPrint = function () {
        var flat = false;
        pl.splice(0, pl.length);
        for (var i in $scope.lists) {
            if ($scope.lists[i].check == true) {
                pl.push($scope.lists[i]);
                flat = true;
            }
        }
        if (flat) {
            localStorage.pl = JSON.stringify(pl);
            window.open("printTM.jsp");

        }
    }

    $scope.sendCenter = function (item) {
        base.post("sample/sendToCenter", {pk: item.PK}).get(function (data) {
            if (data == 'true') {
                steveAl("发送成功", 1000);
            } else {
                steveAl("发送失败", 1000);
            }
        })
    }


    $scope.printRpt = function (item) {

        window.open("sample/printRpt?uuid="+item.UUID + "&print=true");
    }
    $scope.previewRpt = function (item) {

        window.open("sample/printRpt?uuid="+item.UUID + "&print=false");
    }



    $('#datetimepicker').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd ',
        startView: 3,
        autoclose: true,
        minView: 2
    }).on('changeDate', function (ev) {
        $scope.date = ev.date.Format("yyyy-MM-dd");
    });

});




</script>
